package cn.woochen.functionwidget.util

import android.os.SystemClock
import android.util.Log
import android.view.View

import java.util.Calendar

/**
 * 避免短时间多次单击
 * @author chenwuchao
 * @time 2017/9/12 15:06
 * @desc 1s之内只能进行一次单击操作
 */
abstract class PerfectClickListener : View.OnClickListener {
    private var lastClickTime: Long = 0
    private var id = -1

    override fun onClick(v: View?) {
        val currentTime = SystemClock.currentThreadTimeMillis()
          val mId = v?.id!!;
        if (id != mId) {
            id = mId
            lastClickTime = currentTime
            onNoDoubleClick(v)
            return
        }
        if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime
            onNoDoubleClick(v)
        }else{
            Log.e("eee","操作太频繁啦${currentTime - lastClickTime}")
        }
    }

    protected abstract fun onNoDoubleClick(v: View?)

    companion object {
        const val MIN_CLICK_DELAY_TIME = 1000
    }
}
